<?php
namespace app\index\controller;

use app\BaseController;
use  think\facade\View;
use  think\facade\Config; 
use  think\facade\Session; 
use  think\Request;
use  app\common\system\LoginService;
use  app\common\validate\UserValidate;



class Login extends BaseController
{
   //登录界面
    public function login()
    {
  
      if(request()->isPost()){       
        $param = request()->post();    
       //执行登录
        $data = LoginService::login($param);
       session('user', $data['user']->toArray());   
       session('group', $data['group_id']);
        success('登录成功');
      }else { 
        return view('index');
      }
      
    }
  //退出登录
    public function logout()
    {
      $user= session('users');
      LoginService::logout($user);
      success('退出成功');
    }

    //修改密码
    public function changePassword(){
      if(request()->isPost()){
          $param = request()->post(); 
          $data = LoginService::changpass($param);     
          if($data){
            success('密码修改成功');
          }else{
            error('密码修改失败');
          }
      }      
      
    }
}
